package com.briup.day24;

import com.briup.day24.bean.Student;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;

public class Test_WriteList {
    public static void main(String[] args) throws Exception {
        //序列化对象 将对象写入文件中 将对象存放在集合 将集合对象写入文件
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("01-Basic/src/dir/list.txt"));
        List<Student> list = new ArrayList<Student>();
        Student s1 = new Student("zs",19);
        list.add(s1);
        Student s2 = new Student("tom",20);
        list.add(s2);
        Student s3 = new Student("terry",21);
        list.add(s3);
        //将集合对象写入到list.txt
        oos.writeObject(list);
        System.out.println(list);
        System.out.println("写入完成");
        oos.close();
    }
}
